/*******************************************************************************
 * Copyright (c) 2011 EclipseDevX.org and others.
 * 
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at:
 * 
 *     http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipsedevx.core.graphing;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class GraphTestView extends ViewPart {

	/**
	 * The ID of the view as specified by the extension.
	 */
	public static final String ID = "org.eclipsedevx.core.graphing.GraphTestView";

	private static final String CHART_URL_1 = "https://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chl=Hello|World";
	private static final String CHART_URL_2 = "http://chart.apis.google.com/chart?chxr=0,0,160&chxt=x&chbh=a&cht=bhs&chco=4D89F9,C6D9FD&chds=0,160,0,160&chd=t:10,50,60,80,40,60,30|50,60,100,40,30,40,30&chtt=Horizontal+bar+chart";
	private static final String CHART_URL_3 = "http://chart.apis.google.com/chart?chxr=0,0,2750&chxt=y&cht=lc&chco=3072F3&chds=0,2500&chd=t:787.553,1115.255,1307.616,1535.038,1813.098,1678.481,1738.126,1562.506,1563.512,1757.503,1889.952,2227.111,2026.646,2056.46,2182.829,1916.671,1637.504,1502.306,1497.994,1421.31&chg=14.3,-1,1,1&chls=2,4,0";

	private Action action1;
	private Action action2;
	private Action action3;
	
	private GraphControl graph;

	/**
	 * The constructor.
	 */
	public GraphTestView() {
		
	}

	/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
	public void createPartControl(Composite parent) {
		parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
		graph = new GraphControl(parent, SWT.NONE);
		
		graph.setGraphUrl(CHART_URL_1);
		
		makeActions();
		contributeToActionBars();
	}

	private void contributeToActionBars() {
		IActionBars bars = getViewSite().getActionBars();
		fillLocalToolBar(bars.getToolBarManager());
	}

	private void fillLocalToolBar(IToolBarManager manager) {
		manager.add(action1);
		manager.add(action2);
		manager.add(action3);
	}

	private void makeActions() {
		action1 = new Action() {
			public void run() {
				graph.setGraphUrl(CHART_URL_1);
			}
		};
		action1.setText("Action 1");
		action1.setToolTipText("Action 1 tooltip");
		action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
			getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
		
		action2 = new Action() {
			public void run() {
				graph.setGraphUrl(CHART_URL_2);
			}
		};
		action2.setText("Action 2");
		action2.setToolTipText("Action 2 tooltip");
		action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
				getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
		
		action3 = new Action() {
			public void run() {
				graph.setGraphUrl(CHART_URL_3);
			}
		};
		action3.setText("Action 3");
		action3.setToolTipText("Action 3 tooltip");
		action3.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
				getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
	}

	public void setFocus() {
		
	}
	
}
